package com.tjcu.service.impl;

import com.tjcu.dao.GroupDao;
import com.tjcu.entity.Clazz;
import com.tjcu.entity.Group;
import com.tjcu.entity.Student;
import com.tjcu.service.GroupService;
import com.tjcu.utils.MybatisUtil;

import java.util.List;

/**
 * @author 王恒杰
 * @version 1.0
 * @date 2021/11/2 20:20
 * @email 1078993387@qq.com
 * @Address 天津
 * @Description:
 */
public class GroupServiceImpl implements GroupService {

    @Override
    public void addGroup(Group group) {
        GroupDao mapper = (GroupDao) MybatisUtil.getMapper(GroupDao.class);
        mapper.insertGroup(group);
        //关闭链接，提交事务
        MybatisUtil.commit();
    }

    @Override
    public List showGroupAndClass() {
        GroupDao mapper = (GroupDao) MybatisUtil.getMapper(GroupDao.class);
        List list = mapper.selectGroupAndClass();
        //关闭链接
        MybatisUtil.close();

        return list;
    }

    @Override
    public void dropGroup(Integer id) {
        GroupDao mapper = (GroupDao) MybatisUtil.getMapper(GroupDao.class);
       mapper.deleteGroup(id);
        //关闭链接，提交事务
        MybatisUtil.commit();
    }

    @Override
    public List<Clazz> showClazzName() {
        GroupDao mapper = (GroupDao) MybatisUtil.getMapper(GroupDao.class);
        List<Clazz> list = mapper.selectClazzName();
        //关闭链接
        MybatisUtil.close();
        return list;
    }

    @Override
    public List selectStudentsByGroup() {
        GroupDao mapper = (GroupDao) MybatisUtil.getMapper(GroupDao.class);
        List list = mapper.selectStudentsByGroup();
        MybatisUtil.close();
        return list;
    }


}
